package com.cyl.wms.controller;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Page;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.enums.BusinessType;
import com.cyl.wms.convert.AssetItemConvert;
import com.cyl.wms.domain.AssetItem;
import com.cyl.wms.pojo.query.AssetItemQuery;
import com.cyl.wms.service.AssetItemService;
import com.cyl.wms.pojo.vo.AssetItemVO;
import com.ruoyi.common.utils.poi.ExcelUtil;
/**
 * 资产清单表Controller
 *
 * @author zcc
 * @date 2024-05-21
 */
@Api(description ="资产清单表接口列表")
@RestController
@RequestMapping("/wms/assetItem")
public class AssetItemController extends BaseController {

    @Autowired
    private AssetItemService service;

    @Autowired
    private AssetItemConvert convert;

    @ApiOperation("查询资产清单表列表")
    @PostMapping("/list")
    public ResponseEntity<Page<AssetItem>> list(@RequestBody AssetItemQuery query, Pageable page) {
        List<AssetItem> list = service.selectList(query, page);
        return ResponseEntity.ok(new PageImpl<>(list, page, ((com.github.pagehelper.Page)list).getTotal()));
    }

    @ApiOperation("导出资产清单表列表")
    @PreAuthorize("@ss.hasPermi('wms:assetItem:export')")
    @Log(title = "资产清单表", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public ResponseEntity<String> export(AssetItemQuery query) {
        List<AssetItem> list = service.selectList(query, null);
        ExcelUtil<AssetItemVO> util = new ExcelUtil<>(AssetItemVO.class);
        return ResponseEntity.ok(util.writeExcel(convert.dos2vos(list), "资产清单表数据"));
    }

    @ApiOperation("获取资产清单表详细信息")
    @PreAuthorize("@ss.hasPermi('wms:assetItem:query')")
    @GetMapping(value = "/{id}")
    public ResponseEntity<AssetItem> getInfo(@PathVariable("id") Integer id) {
        AssetItem res = service.selectById(id);

        return ResponseEntity.ok(res);
    }

    @ApiOperation("新增资产清单表")
    @PreAuthorize("@ss.hasPermi('wms:assetItem:add')")
    @Log(title = "资产清单表", businessType = BusinessType.INSERT)
    @PostMapping
    public ResponseEntity<Integer> add(@RequestBody AssetItem assetItem) {
        return ResponseEntity.ok(service.insert(assetItem));
    }

    @ApiOperation("修改资产清单表")
    @PreAuthorize("@ss.hasPermi('wms:assetItem:edit')")
    @Log(title = "资产清单表", businessType = BusinessType.UPDATE)
    @PutMapping
    public ResponseEntity<Integer> edit(@RequestBody AssetItem assetItem) {
        return ResponseEntity.ok(service.update(assetItem));
    }

    @ApiOperation("删除资产清单表")
    @PreAuthorize("@ss.hasPermi('wms:assetItem:remove')")
    @Log(title = "资产清单表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public ResponseEntity<Integer> remove(@PathVariable Long[] ids) {
        return ResponseEntity.ok(service.deleteByIds(ids));
    }
}
